1 Imports System.Data.SqlClient
2 Imports System.IO
3
4 Public Class frmBusFeePayment_Staff
5     Sub Calculate()
6         Dim num1, num2 As Double
7         num1 = CDbl(Val(txtBusFee.Text) + Val(txtFine.Text) + Val(txtPreviousDue.Text) - Val(txtDiscount.Text))
8         num1 = Math.Round(num1,
2)
9         txtGrandTotal.Text = num1
10         num2 = Val(txtGrandTotal.Text) - Val(txtTotalPaid.Text)
11         num2 = Math.Round(num2,
2)
12         txtBalance.Text = num2
13     End Sub
14     Sub Print()
15         Try
16             Cursor = Cursors.WaitCursor
17             Timer1.Enabled = True
18             Dim rpt As New rptBusFeeReceipt_Staff
'The report you created.
19             Dim myConnection As SqlConnection
20             Dim MyCommand As New SqlCommand()
21             Dim myDA As New SqlDataAdapter()
22             Dim myDS As New DataSet
'The DataSet you created.
23             myConnection = New SqlConnection(cs)
24             MyCommand.Connection = myConnection
25             MyCommand.CommandText =
"SELECT BusFeePayment_Staff.Id, BusFeePayment_Staff.BFP_ID, BusFeePayment_Staff.PaymentID, BusFeePayment_Staff.BusHolderID, BusFeePayment_Staff.Session, BusFeePayment_Staff.Installment,BusFeePayment_Staff.TotalFee, BusFeePayment_Staff.DiscountPer, BusFeePayment_Staff.DiscountAmt, BusFeePayment_Staff.PreviousDue, BusFeePayment_Staff.Fine, BusFeePayment_Staff.GrandTotal, BusFeePayment_Staff.TotalPaid, BusFeePayment_Staff.ModeOfPayment, BusFeePayment_Staff.PaymentModeDetails, BusFeePayment_Staff.PaymentDate, BusFeePayment_Staff.PaymentDue,BusCardHolder_Staff.BCH_ID, BusCardHolder_Staff.StaffID, BusCardHolder_Staff.BusNo, BusCardHolder_Staff.Location, BusCardHolder_Staff.JoiningDate, BusCardHolder_Staff.Status, Staff.St_ID,Staff.StaffID AS Expr1, Staff.StaffName, Staff.DateOfJoining, Staff.Gender, Staff.FatherName, Staff.TemporaryAddress, Staff.PermanentAddress, Staff.Designation, Staff.Qualifications, Staff.DOB, Staff.PhoneNo,Staff.MobileNo, Staff.Photo, Staff.ClassType, Staff.SchoolID, Staff.AccountName, Staff.AccountNumber, Staff.Bank, Staff.Branch, Staff.IFSCcode, Staff.Salary, SchoolInfo.S_Id,SchoolInfo.SchoolName, SchoolInfo.Address, SchoolInfo.ContactNo, SchoolInfo.AltContactNo, SchoolInfo.FaxNo, SchoolInfo.Email , SchoolInfo.Website, SchoolInfo.Logo, SchoolInfo.RegistrationNo,SchoolInfo.DiseNo, SchoolInfo.IndexNo, SchoolInfo.EstablishedYear, SchoolInfo.Class, SchoolInfo.SchoolType FROM BusFeePayment_Staff INNER JOIN BusCardHolder_Staff ON BusFeePayment_Staff.BusHolderID = BusCardHolder_Staff.BCH_ID INNER JOIN Staff ON BusCardHolder_Staff.StaffID = Staff.St_ID INNER JOIN SchoolInfo ON Staff.SchoolID = SchoolInfo.S_Id where BusFeePayment_Staff.PaymentID='" & txtFeePaymentID.Text & "'"
26             MyCommand.CommandType = CommandType.Text
27             myDA.SelectCommand = MyCommand
28             myDA.Fill(myDS,
"SchoolInfo")
29             myDA.Fill(myDS,
"Staff")
30             myDA.Fill(myDS,
"BusCardHolder_Staff")
31             myDA.Fill(myDS,
"BusFeePayment_Staff")
32             rpt.SetDataSource(myDS)
33             rpt.SetParameterValue(
"p1", txtStaffID.Text)
34             frmReport.CrystalReportViewer1.ReportSource = rpt
35             frmReport.ShowDialog()
36         Catch ex As Exception
37             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
38         End Try
39     End Sub
40     Private Function GenerateID() As String
41         con = New SqlConnection(cs)
42         Dim
value As String = "0000"
43         Try
44             
' Fetch the latest ID from the database
45             con.Open()
46             cmd = New SqlCommand(
"SELECT TOP 1 (BFP_ID) FROM BusFeePayment_Staff ORDER BY BFP_ID DESC", con)
47             rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
48             If rdr.HasRows Then
49                 rdr.Read()
50                 
value = rdr.Item("BFP_ID")
51             End If
52             rdr.Close()
53             
' Increase the ID by 1
54             
value += 1
55             
' Because incrementing a string with an integer removes 0's
56             
' we need to replace them. If necessary.
57             If
value <= 9 Then 'Value is between 0 and 10
58                 
value = "000" & value
59             ElseIf
value <= 99 Then 'Value is between 9 and 100
60                 
value = "00" & value
61             ElseIf
value <= 999 Then 'Value is between 999 and 1000
62                 
value = "0" & value
63             End If
64         Catch ex As Exception
65             
' If an error occurs, check the connection state and close it if necessary.
66             If con.State = ConnectionState.Open Then
67                 con.Close()
68             End If
69             
value = "0000"
70         End Try
71         Return
value
72     End Function
73     Public Sub auto()
74         Try
75             txtBFPId.Text = GenerateID()
76             Dim a As String = txtStaffID.Text
77             txtFeePaymentID.Text =
"SBFP-" + GenerateID() + "-" + a
78         Catch ex As Exception
79             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
80         End Try
81     End Sub
82
83     Sub Reset()
84         cmbInstallment.DropDownStyle = ComboBoxStyle.DropDownList
85         txtStaffID.Text =
""
86         txtBusFee.Text =
""
87         txtPaymentModeDetails.Text =
""
88         txtBalance.Text =
""
89         txtDiscount.Text =
""
90         txtDiscountPer.Text =
""
91         txtDesignation.Text =
""
92         txtFine.Text =
""
93         txtGrandTotal.Text =
""
94         txtPreviousDue.Text =
""
95         txtLocation.Text =
""
96         cmbSession.SelectedIndex = -
1
97         txtStaffName.Text =
""
98         txtTotalPaid.Text =
""
99         cmbPaymentMode.SelectedIndex = -
1
100         cmbInstallment.SelectedIndex = -
1
101         dtpPaymentDate.Text = Now
102         btnSave.Enabled = True
103         cmbInstallment.Enabled = True
104         cmbSession.Enabled = True
105         btnUpdate.Enabled = False
106         btnDelete.Enabled = False
107         btnPrint.Enabled = False
108         Button2.Enabled = True
109         dtpPaymentDate.Enabled = True
110         cmbSession.DropDownStyle = ComboBoxStyle.DropDownList
111     End Sub
112
113     Sub Fill()
114         Try
115             con = New SqlConnection(cs)
116             con.Open()
117             cmd = con.CreateCommand()
118             cmd.CommandText =
"SELECT Discount from Discount_Staff where StaffID=@d1"
119             cmd.Parameters.AddWithValue(
"@d1", txtSt_ID.Text)
120             rdr = cmd.ExecuteReader()
121             If rdr.Read() Then
122                 txtDiscountPer.Text = rdr.GetValue(
0)
123                 Dim num As Double
124                 num = CDbl((Val(txtBusFee.Text) * Val(txtDiscountPer.Text)) /
100)
125                 num = Math.Round(num,
2)
126                 txtDiscount.Text = num
127             End If
128             If (rdr IsNot Nothing) Then
129                 rdr.Close()
130             End If
131             If con.State = ConnectionState.Open Then
132                 con.Close()
133             End If
134
135             Calculate()
136         Catch ex As Exception
137             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
138         End Try
139     End Sub
140     Sub fillSession()
141         Try
142             con = New SqlConnection(cs)
143             con.Open()
144             adp = New SqlDataAdapter()
145             adp.SelectCommand = New SqlCommand(
"SELECT distinct (Session) FROM Session_Master", con)
146             ds = New DataSet(
"ds")
147             adp.Fill(ds)
148             dtable = ds.Tables(
0)
149             cmbSession.Items.Clear()
150             For Each drow As DataRow In dtable.Rows
151                 cmbSession.Items.Add(drow(
0).ToString())
152             Next
153         Catch ex As Exception
154             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
155         End Try
156     End Sub
157     Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
158         frmBusCardHolder_StaffRecord.lblSet.Text =
"Bus Fee Payment"
159         frmBusCardHolder_StaffRecord.Reset()
160         frmBusCardHolder_StaffRecord.ShowDialog()
161     End Sub
162
163     Private Sub btnGetFeeList_Click(sender As System.Object, e As System.EventArgs) Handles btnGetFeeList.Click
164         Try
165             If txtStaffID.Text =
"" Then
166                 MessageBox.Show(
"Please retrieve bus holder info", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
167                 txtStaffID.Focus()
168                 Return
169             End If
170             If cmbSession.Text =
"" Then
171                 MessageBox.Show(
"Please select session", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
172                 cmbSession.Focus()
173                 Return
174             End If
175             If cmbInstallment.Text =
"" Then
176                 MessageBox.Show(
"Please select installment", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
177                 cmbInstallment.Focus()
178                 Return
179             End If
180             con = New SqlConnection(cs)
181             con.Open()
182             cmd = con.CreateCommand()
183             cmd.CommandText =
"SELECT Charges from Installment_Bus where Installment=@d1 and Location=@d2"
184             cmd.Parameters.AddWithValue(
"@d1", cmbInstallment.Text)
185             cmd.Parameters.AddWithValue(
"@d2", txtLocation.Text)
186             rdr = cmd.ExecuteReader()
187             If rdr.Read() Then
188                 txtBusFee.Text = rdr.GetValue(
0)
189             End If
190             If (rdr IsNot Nothing) Then
191                 rdr.Close()
192             End If
193             If con.State = ConnectionState.Open Then
194                 con.Close()
195             End If
196             con = New SqlConnection(cs)
197             con.Open()
198             cmd = con.CreateCommand()
199             cmd.CommandText =
"SELECT Sum(PaymentDue-PreviousDue) from BusFeePayment_Staff where BusHolderID=@d1 group by BusHolderID"
200             cmd.Parameters.AddWithValue(
"@d1", txtBusHolderID.Text)
201             rdr = cmd.ExecuteReader()
202             If rdr.Read() Then
203                 txtPreviousDue.Text = rdr.GetValue(
0)
204             Else
205                 txtPreviousDue.Text =
0
206             End If
207             If (rdr IsNot Nothing) Then
208                 rdr.Close()
209             End If
210             If con.State = ConnectionState.Open Then
211                 con.Close()
212             End If
213             Fill()
214         Catch ex As Exception
215             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
216         End Try
217     End Sub
218
219     Private Sub btnNew_Click(sender As System.Object, e As System.EventArgs) Handles btnNew.Click
220         Reset()
221         Reset()
222     End Sub
223
224     Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
225         If Len(Trim(txtStaffID.Text)) =
0 Then
226             MessageBox.Show(
"Please retrieve bus holder info", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
227             txtStaffID.Focus()
228             Exit Sub
229         End If
230         If Len(Trim(cmbSession.Text)) =
0 Then
231             MessageBox.Show(
"Please select session", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
232             cmbSession.Focus()
233             Exit Sub
234         End If
235         If Len(Trim(cmbInstallment.Text)) =
0 Then
236             MessageBox.Show(
"Please select installment", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
237             cmbInstallment.Focus()
238             Exit Sub
239         End If
240         If Len(Trim(txtFine.Text)) =
0 Then
241             MessageBox.Show(
"Please enter fine", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
242             txtFine.Focus()
243             Exit Sub
244         End If
245         If Len(Trim(cmbPaymentMode.Text)) =
0 Then
246             MessageBox.Show(
"Please select Payment Mode", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
247             cmbPaymentMode.Focus()
248             Exit Sub
249         End If
250         If Len(Trim(txtTotalPaid.Text)) =
0 Then
251             MessageBox.Show(
"Please enter total paid", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
252             txtTotalPaid.Focus()
253             Exit Sub
254         End If
255         If Val(txtBalance.Text) <
0 Then
256             MessageBox.Show(
"Balance is not possible less than zero", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error)
257             Exit Sub
258         End If
259         Try
260             con = New SqlConnection(cs)
261             con.Open()
262             Dim ct As String =
"select Session,BusHolderID,Installment from BusFeePayment_Staff where Session=@d1 and BusHolderID=@d2 and Installment=@d3"
263             cmd = New SqlCommand(ct)
264             cmd.Connection = con
265             cmd.Parameters.AddWithValue(
"@d1", cmbSession.Text)
266             cmd.Parameters.AddWithValue(
"@d2", txtBusHolderID.Text)
267             cmd.Parameters.AddWithValue(
"@d3", cmbInstallment.Text)
268             rdr = cmd.ExecuteReader()
269             If rdr.Read Then
270                 MessageBox.Show(
"Already paid", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
271                 If Not rdr Is Nothing Then
272                     rdr.Close()
273                 End If
274                 Exit Sub
275             End If
276             auto()
277             con = New SqlConnection(cs)
278             con.Open()
279             Dim cb As String =
"insert into BusFeePayment_Staff(BFP_ID, PaymentID, BusHolderID, Session,installment,TotalFee, DiscountPer, DiscountAmt, PreviousDue, Fine, GrandTotal, TotalPaid, ModeOfPayment, PaymentModeDetails, PaymentDate, PaymentDue) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13,@d14,@d15,@d16)"
280             cmd = New SqlCommand(cb)
281             cmd.Connection = con
282             cmd.Parameters.AddWithValue(
"@d1", txtBFPId.Text)
283             cmd.Parameters.AddWithValue(
"@d2", txtFeePaymentID.Text)
284             cmd.Parameters.AddWithValue(
"@d3", txtBusHolderID.Text)
285             cmd.Parameters.AddWithValue(
"@d4", cmbSession.Text)
286             cmd.Parameters.AddWithValue(
"@d5", cmbInstallment.Text)
287             cmd.Parameters.AddWithValue(
"@d6", txtBusFee.Text)
288             cmd.Parameters.AddWithValue(
"@d7", txtDiscountPer.Text)
289             cmd.Parameters.AddWithValue(
"@d8", txtDiscount.Text)
290             cmd.Parameters.AddWithValue(
"@d9", txtPreviousDue.Text)
291             cmd.Parameters.AddWithValue(
"@d10", txtFine.Text)
292             cmd.Parameters.AddWithValue(
"@d11", txtGrandTotal.Text)
293             cmd.Parameters.AddWithValue(
"@d12", txtTotalPaid.Text)
294             cmd.Parameters.AddWithValue(
"@d13", cmbPaymentMode.Text)
295             cmd.Parameters.AddWithValue(
"@d14", txtPaymentModeDetails.Text)
296             cmd.Parameters.AddWithValue(
"@d15", dtpPaymentDate.Value)
297             cmd.Parameters.AddWithValue(
"@d16", txtBalance.Text)
298             cmd.ExecuteNonQuery()
299             Dim st As String =
"added the new bus fee payment entry having payment id '" & txtFeePaymentID.Text & "'"
300             LogFunc(lblUser.Text, st)
301             MessageBox.Show(
"Successfully paid", "Fee", MessageBoxButtons.OK, MessageBoxIcon.Information)
302             btnSave.Enabled = False
303             con.Close()
304             Print()
305         Catch ex As Exception
306             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
307         End Try
308     End Sub
309
310     Private Sub btnDelete_Click(sender As System.Object, e As System.EventArgs) Handles btnDelete.Click
311         Try
312             If MessageBox.Show(
"Do you really want to delete the record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = Windows.Forms.DialogResult.Yes Then
313                 delete_records()
314             End If
315         Catch ex As Exception
316             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
317         End Try
318     End Sub
319     Private Sub delete_records()
320         Try
321             Dim RowsAffected As Integer =
0
322             con = New SqlConnection(cs)
323             con.Open()
324             Dim cq As String =
"delete from BusFeePayment_Staff where ID= " & txtID.Text & ""
325             cmd = New SqlCommand(cq)
326             cmd.Connection = con
327             RowsAffected = cmd.ExecuteNonQuery()
328             If RowsAffected >
0 Then
329                 Dim st As String =
"deleted the bus fee payment entry having payment id '" & txtFeePaymentID.Text & "'"
330                 LogFunc(lblUser.Text, st)
331                 MessageBox.Show(
"Successfully deleted", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
332                 Reset()
333                 Reset()
334             Else
335                 MessageBox.Show(
"No record found", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information)
336                 Reset()
337                 Reset()
338             End If
339             con.Close()
340         Catch ex As Exception
341             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
342         End Try
343     End Sub
344
345     Private Sub btnUpdate_Click(sender As System.Object, e As System.EventArgs) Handles btnUpdate.Click
346         If Len(Trim(txtStaffID.Text)) =
0 Then
347             MessageBox.Show(
"Please retrieve bus holder info", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
348             txtStaffID.Focus()
349             Exit Sub
350         End If
351
352         If Len(Trim(cmbInstallment.Text)) =
0 Then
353             MessageBox.Show(
"Please select installment", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
354             cmbInstallment.Focus()
355             Exit Sub
356         End If
357         If Len(Trim(txtFine.Text)) =
0 Then
358             MessageBox.Show(
"Please enter fine", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
359             txtFine.Focus()
360             Exit Sub
361         End If
362         If Len(Trim(cmbPaymentMode.Text)) =
0 Then
363             MessageBox.Show(
"Please select Payment Mode", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
364             cmbPaymentMode.Focus()
365             Exit Sub
366         End If
367         If Len(Trim(txtTotalPaid.Text)) =
0 Then
368             MessageBox.Show(
"Please enter total paid", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
369             txtTotalPaid.Focus()
370             Exit Sub
371         End If
372         If Val(txtBalance.Text) <
0 Then
373             MessageBox.Show(
"Balance is not possible less than zero", "Input error", MessageBoxButtons.OK, MessageBoxIcon.Error)
374             Exit Sub
375         End If
376         Try
377             
'con = New SqlConnection(cs)
378             
'con.Open()
379             
'Dim ct As String = "select PaymentDate from BusFeePayment_Staff where AdmissionNo=@d1"
380             
'cmd = New SqlCommand(ct)
381             
'cmd.Connection = con
382             
'cmd.Parameters.AddWithValue("@d1", txtAdmissionNo.Text)
383             
'Dim da As New SqlDataAdapter(cmd)
384             
'Dim ds As DataSet = New DataSet()
385             
'da.Fill(ds)
386             
'If ds.Tables(0).Rows.Count > 0 Then
387             
'If dtpPaymentDate.Value.Date < ds.Tables(0).Rows(0)("PaymentDate") Then
388             
'MessageBox.Show("updating old record is not allowed when student has been already paid fee again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
389             
'End If
390             
'Exit Sub
391             
'End If
392             
'con.Close()
393             con = New SqlConnection(cs)
394             con.Open()
395             Dim cb As String =
"Update BusFeePayment_Staff set BFP_ID=@d1, PaymentID=@d2, BusHolderID=@d3, Session=@d4, Installment=@d5,TotalFee=@d6, DiscountPer=@d7, DiscountAmt=@d8, PreviousDue=@d9, Fine=@d10, GrandTotal=@d11, TotalPaid=@d12, ModeOfPayment=@d13, PaymentModeDetails=@d14,PaymentDue=@d15 where ID= " & txtID.Text & ""
396             cmd = New SqlCommand(cb)
397             cmd.Connection = con
398             cmd.Parameters.AddWithValue(
"@d1", txtBFPId.Text)
399             cmd.Parameters.AddWithValue(
"@d2", txtFeePaymentID.Text)
400             cmd.Parameters.AddWithValue(
"@d3", txtBusHolderID.Text)
401             cmd.Parameters.AddWithValue(
"@d4", cmbSession.Text)
402             cmd.Parameters.AddWithValue(
"@d5", cmbInstallment.Text)
403             cmd.Parameters.AddWithValue(
"@d6", txtBusFee.Text)
404             cmd.Parameters.AddWithValue(
"@d7", txtDiscountPer.Text)
405             cmd.Parameters.AddWithValue(
"@d8", txtDiscount.Text)
406             cmd.Parameters.AddWithValue(
"@d9", txtPreviousDue.Text)
407             cmd.Parameters.AddWithValue(
"@d10", txtFine.Text)
408             cmd.Parameters.AddWithValue(
"@d11", txtGrandTotal.Text)
409             cmd.Parameters.AddWithValue(
"@d12", txtTotalPaid.Text)
410             cmd.Parameters.AddWithValue(
"@d13", cmbPaymentMode.Text)
411             cmd.Parameters.AddWithValue(
"@d14", txtPaymentModeDetails.Text)
412             cmd.Parameters.AddWithValue(
"@d15", txtBalance.Text)
413             cmd.ExecuteNonQuery()
414             con.Close()
415             Dim st As String =
"updated the bus fee payment entry having payment id '" & txtFeePaymentID.Text & "'"
416             LogFunc(lblUser.Text, st)
417             MessageBox.Show(
"Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
418             btnUpdate.Enabled = False
419             con.Close()
420         Catch ex As Exception
421             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
422         End Try
423     End Sub
424
425     Private Sub txtFine_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtFine.KeyPress
426         Dim keyChar = e.KeyChar
427
428         If Char.IsControl(keyChar) Then
429             
'Allow all control characters.
430         ElseIf Char.IsDigit(keyChar) OrElse keyChar =
"."c Then
431             Dim text = Me.txtFine.Text
432             Dim selectionStart = Me.txtFine.SelectionStart
433             Dim selectionLength = Me.txtFine.SelectionLength
434
435             text = text.Substring(
0, selectionStart) & keyChar & text.Substring(selectionStart + selectionLength)
436
437             If Integer.TryParse(text, New Integer) AndAlso text.Length >
16 Then
438                 
'Reject an integer that is longer than 16 digits.
439                 e.Handled = True
440             ElseIf Double.TryParse(text, New Double) AndAlso text.IndexOf(
"."c) < text.Length - 3 Then
441                 
'Reject a real number with two many decimal places.
442                 e.Handled = False
443             End If
444         Else
445             
'Reject all other characters.
446             e.Handled = True
447         End If
448     End Sub
449
450     Private Sub txtTotalPaid_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtTotalPaid.KeyPress
451         Dim keyChar = e.KeyChar
452
453         If Char.IsControl(keyChar) Then
454             
'Allow all control characters.
455         ElseIf Char.IsDigit(keyChar) OrElse keyChar =
"."c Then
456             Dim text = Me.txtTotalPaid.Text
457             Dim selectionStart = Me.txtTotalPaid.SelectionStart
458             Dim selectionLength = Me.txtTotalPaid.SelectionLength
459
460             text = text.Substring(
0, selectionStart) & keyChar & text.Substring(selectionStart + selectionLength)
461
462             If Integer.TryParse(text, New Integer) AndAlso text.Length >
16 Then
463                 
'Reject an integer that is longer than 16 digits.
464                 e.Handled = True
465             ElseIf Double.TryParse(text, New Double) AndAlso text.IndexOf(
"."c) < text.Length - 3 Then
466                 
'Reject a real number with two many decimal places.
467                 e.Handled = False
468             End If
469         Else
470             
'Reject all other characters.
471             e.Handled = True
472         End If
473     End Sub
474
475     Private Sub txtTotalPaid_Validating(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles txtTotalPaid.Validating
476         If Val(txtTotalPaid.Text) > Val(txtGrandTotal.Text) Then
477             MessageBox.Show(
"Total Pay can not be more than grand total", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
478             txtTotalPaid.Text =
""
479             txtTotalPaid.Focus()
480             Exit Sub
481         End If
482     End Sub
483
484     Private Sub txtFine_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtFine.TextChanged
485         Fill()
486     End Sub
487
488     Private Sub txtTotalPaid_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtTotalPaid.TextChanged
489         Fill()
490     End Sub
491
492     Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
493         Me.Close()
494     End Sub
495
496     Private Sub btnGetData_Click(sender As System.Object, e As System.EventArgs) Handles btnGetData.Click
497         frmBusFeePayment_StaffRecord.lblSet.Text =
"Bus Fee Payment"
498         frmBusFeePayment_StaffRecord.Reset()
499         frmBusFeePayment_StaffRecord.ShowDialog()
500     End Sub
501     Sub fillInstallment()
502         Try
503             con = New SqlConnection(cs)
504             con.Open()
505             Dim ct As String =
"SELECT distinct RTRIM(Installment) FROM Installment_Bus where Location=@d1"
506             cmd = New SqlCommand(ct)
507             cmd.Parameters.AddWithValue(
"@d1", txtLocation.Text)
508             cmd.Connection = con
509             rdr = cmd.ExecuteReader()
510             cmbInstallment.Items.Clear()
511             While rdr.Read
512                 cmbInstallment.Items.Add(rdr(
0))
513             End While
514             con.Close()
515         Catch ex As Exception
516             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
517         End Try
518     End Sub
519     Private Sub frmBusFeePayment_Staff_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
520         fillInstallment()
521         fillSession()
522     End Sub
523
524     Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
525         Cursor = Cursors.Default
526         Timer1.Enabled = False
527     End Sub
528
529     Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
530         Print()
531     End Sub
532 End Class


Gõ tìm kiếm nhanh...